import datetime
import typing as tp

import pydantic

from .jobs import JobVarType
from .executors import BaseExecutor


class Task(pydantic.BaseModel):
    aps_job_id: str  # aps作业id
    job: JobVarType     # 作业配置
    log_root_path: str    # 任务日志根目录
    is_delayed: bool = False    # 是否延迟

    trigger_index: int = 1  # 触发次数
    continue_by_reboot: bool = False    # 由于重启步骤继续运行
    running_executors: tp.List[str] = []    # 该任务正在运行的执行器

    current_step_index: int = 1     # 当前步骤索引
    current_step_start_time: tp.Optional[datetime.datetime] = None

    log_path: str = None
    loguru_log_path_id: int = 0   # loguru.logger.add

    start_time: tp.Optional[datetime.datetime] = None

    viztracer_result_json: str = None

    executors: tp.Set[tp.Any] = set()   # 当前任务正在运行的执行器

    runner: tp.Optional[tp.Any] = None    # 当前任务的runner
